package net.oschina.simpleplus.controller;

import java.util.HashMap;
import java.util.Map;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import net.oschina.simpleplus.generate.Generator;
import net.oschina.simpleplus.parameter.WebBuildParameters;

@Controller
public class IndexController {

    @GetMapping("/")
    public String index() {
        return "/index";
    }

    @RequestMapping(value="/build", method= RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> build(WebBuildParameters webBuildParameters) throws Exception {
        Generator.execute(webBuildParameters.getBuildParams());
        Map<String, Object> m = new HashMap<>();
        m.put("code", 1);
        m.put("msg", webBuildParameters.getProjectName());
        return m;
    }

}
